﻿Module ExceptionProcessor

	Public logger As log4net.ILog = log4net.LogManager.GetLogger("log4netSecretaryTool")

	Public Sub UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
		Try
			ExceptionMain(sender, CType(e.ExceptionObject, Exception))
		Catch ex As Exception
			ExceptionMain(sender, ex)
		End Try
	End Sub

	Public Sub ThreadException(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
		ExceptionMain(sender, e.Exception)
	End Sub

	Private Sub ExceptionMain(ByVal sender As Object, ByVal myException As Exception)
		logger.Error("Unhandled Exception: ", myException)

		'Return ExceptionMain(sender, myException, AlwaysCreateMiniDump, AlwaysCompressMiniDump, AlwaysShowInterface, AlwaysKillAppOnError, AlwaysLogMessageSynchronously)
	End Sub

End Module

'Public Class SpecialFolderPatternConverter
'	Inherits log4net.Util.PatternConverter
'	Protected Overrides Sub Convert(writer As System.IO.TextWriter, state As Object)
'		Dim specialFolder As Environment.SpecialFolder = DirectCast([Enum].Parse(GetType(Environment.SpecialFolder), MyBase.[Option], True), Environment.SpecialFolder)
'		writer.Write(Environment.GetFolderPath(specialFolder))
'	End Sub
'End Class